package com.jc.framework.exception;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {
	Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
	
	Map<String,Object> retMap ;
	@ExceptionHandler(value = Exception.class)
	public @ResponseBody Map<String,Object> exceptionHandler(HttpServletRequest request , Exception e){
		log.error("全局异常捕获 , 异常信息 {} , {} " , e.getMessage() , e);
		retMap = new HashMap<String,Object>();
		retMap.put("code", "99999");
		retMap.put("message", e == null ? "未知错误" : e.getMessage());
		return retMap;
	}

}
